package com.tsx.demo;

import com.itextpdf.kernel.colors.Color;
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfPage;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
import com.itextpdf.layout.Document;

import java.nio.file.Paths;

public class DynamicStamp {

    public static void main(String[] args) {
        String dest = Paths.get(Constants.dest, "dynamicStamp.pdf").toString();
        try {
            PdfWriter writer = new PdfWriter(dest);

            // Creating a PdfDocument object
            PdfDocument pdfDoc = new PdfDocument(writer);

            // Creating a Document object
            Document doc = new Document(pdfDoc);

            // Creating a new page
            PdfPage pdfPage = pdfDoc.addNewPage();

            // Creating a PdfCanvas object
            PdfCanvas canvas = new PdfCanvas(pdfPage);

            // Setting color to the circle
            Color color = ColorConstants.RED;
            canvas.setColor(color, true);

            // creating a circle
            canvas.circle(300, 400, 200);

            // Filling the circle
            canvas.fill();

            // Closing the document
            doc.close();

            System.out.println("Object drawn on pdf successfully");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}